#include <qobject.h>
#include <qstring.h>
#include <pluginGl.h>
#include <functional>
#include <qsciscintilla.h>
#include <QCoreApplication>

#include "NddPluginBridge.h"

#define NDD_EXPORTDLL

#if defined(Q_OS_WIN)
#if defined(NDD_EXPORTDLL)
#define NDD_EXPORT __declspec(dllexport)
#else
#define NDD_EXPORT __declspec(dllimport)
#endif
#endif

#ifdef __cplusplus
extern "C" {
#endif

NDD_EXPORT bool NDD_PROC_IDENTIFY(NDD_PROC_DATA* pProcData);
NDD_EXPORT int NDD_PROC_MAIN(QWidget* pNotepad, const QString& strFileName, std::function<QsciScintilla* (QWidget*)>getCurEdit, std::function<bool(QWidget* ,int, void*)> pluginCallBack, NDD_PROC_DATA* procData);


#ifdef __cplusplus
}
#endif


NddPluginBridge* pBridge = nullptr;

std::function<QsciScintilla* (QWidget*)> s_getCurEdit = nullptr;
std::function<bool(QWidget*, int, void*)> s_invokeMainFun = nullptr;

bool NDD_PROC_IDENTIFY(NDD_PROC_DATA* pProcData)
{
    if(pProcData == nullptr)
    {
        return false;
    }
    pProcData->m_strPlugName = QString("Hell Outline");
    pProcData->m_strComment = QString("Hell Outline for Notepad--!");

    pProcData->m_version = QString("v1.0.0");
    pProcData->m_auther = QString("Hell");

    pProcData->m_menuType = 1;

    return true;
}

int NDD_PROC_MAIN(QWidget* pNotepad, const QString& strFileName, std::function<QsciScintilla* (QWidget*)>getCurEdit, std::function<bool(QWidget* ,int, void*)> pluginCallBack, NDD_PROC_DATA* pProcData)
{
    if (pProcData != nullptr)
    {
        pBridge = new NddPluginBridge(pNotepad, pProcData->m_rootMenu, strFileName);
        pBridge->setObjectName("nddplg");
    }
    else
    {
        return -1;
    }

    s_getCurEdit = getCurEdit;
    s_invokeMainFun = pluginCallBack;

    return 0;
}

